//
//  MSRecommenDetailTableVC.m
//  SocietySale
//
//  Created by Mike on 16/11/30.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSRecommenDetailTableVC.h"
#import "MSDetailInfoCell.h"
#import "MSRecommenProjectCell.h"
#import "MSRecommenPeopleCell.h"

@interface MSRecommenDetailTableVC ()
//section头部标题
@property(nonatomic,copy)NSArray *sectionTitleArray;
@end

@implementation MSRecommenDetailTableVC

- (void)viewDidLoad{
    [super viewDidLoad];
    
    self.sectionTitleArray = @[@"周长生 | 业主 ",@"其他项目（3）",@"客户可能认识一下人员"];
}

- (void)setModel:(MSDetailContactModel *)model{
    _model = model;
    NSString *sectionTitle1 = [NSString stringWithFormat:@"%@ | %@",_model.name,_model.contactType];
    self.sectionTitleArray = @[sectionTitle1,@"其他项目（0）",@"客户可能认识一下人员"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.dataArray.count) {
        return [self.dataArray[section] count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {//业主信息
        static NSString *identifier = @"InfoCell";
        MSDetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell==nil) {
            cell = [[MSDetailInfoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.keyLabel.left = 20;
            cell.valueLabel.left = 60;
        }
        if (indexPath.row == [self.dataArray[indexPath.section] count] -1) {
            cell.horizonLineView.hidden = NO;
        }
        else{
            cell.horizonLineView.hidden = YES;
        }
        cell.data = self.dataArray[indexPath.section][indexPath.row];
        return cell;
    }
    else if(indexPath.section == 1){//其他项目
        static NSString *identifier = @"ProjectCell";
        MSRecommenProjectCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell==nil) {
            cell = [[MSRecommenProjectCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.horizonLineView.hidden = YES;
        }
        cell.model = self.dataArray[indexPath.section][indexPath.row];
        return cell;
    }
    else if(indexPath.section == 2){//认识其他人
        static NSString *identifier = @"PeopleCell";
        MSRecommenPeopleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell==nil) {
            cell = [[MSRecommenPeopleCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.horizonLineView.hidden = YES;
        }
        cell.model = self.dataArray[indexPath.section][indexPath.row];
        return cell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 30;
    }
    if (indexPath.section == 1) {
        if ([self.dataArray[indexPath.section] count] - 1 == indexPath.row) {
            return 101;
        }
        return 108;
    }
    if (indexPath.section == 2) {
        return 100;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 60)];
    
    if (section == 0){
        bgView.backgroundColor = [UIColor whiteColor];
        
        UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 18+2.5, 10, 15)];
        blueView.backgroundColor = kBlueColor;
        [bgView addSubview:blueView];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 18, 260, 20)];
        titleLabel.text = self.sectionTitleArray[section];
        titleLabel.textColor = kDarkGrayColor;
        titleLabel.font = HeitiFont(14);
        [bgView addSubview:titleLabel];
        if (section == 1) {
            titleLabel.text = [NSString stringWithFormat:@"其他项目（%ld）",[self.dataArray[section] count]];
        }
    }
    else{
        bgView.backgroundColor = kDefaultViewBackgroundColor;
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 16, 260, 15)];
        titleLabel.text = self.sectionTitleArray[section];
        titleLabel.textColor = kDarkGrayColor;
        titleLabel.font = HeitiFont(14);
        [bgView addSubview:titleLabel];
        
    }
    
    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        return 15;
    }
    return 0.01;
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 20)];
        bgView.backgroundColor = [UIColor whiteColor];
        
        UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 14.4, SCREEN_WIDTH, 0.6)];
        horizonLineView.backgroundColor = kNormalGray;
        [bgView addSubview:horizonLineView];
        
        return bgView;
    }
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end
